package com.aier.admin.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.admin.common.AdminFinalPageSize;
import com.aier.admin.common.AdminIcardData;
import com.aier.admin.entity.IcCard;
import com.aier.admin.service.IAdminAssignCardService;
import com.aier.common.dao.ICommonDAO;

@Scope("prototype")
@Component("adminRecoverCardAction")
public class AdminRecoverCardAction extends AdminBaseAction {

    private static final long serialVersionUID = 1L;

    @Resource(name = "adminAssignCardService")
    private IAdminAssignCardService adminAssignCardService;

    // 当前页
    private int page;
    // 每页显示记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总数
    private int count;

    private List<IcCard> icCards;

    private int s;

    private String ichead;
    private String icbody1;
    private String icbody2;

    private Integer pid;

    @Override
    public String execute() {
        return SUCCESS;
    }

    /**
     * 查询未分派的卡
     * 
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchAssignCard() {

        if (page <= 0) {
            page = 1;
        }
        Map<String, Object> map = null;
        map = adminAssignCardService.searchAssignProxyCard(
                AdminIcardData.ICARD_STATE_ASSIGNPROXY,pid, page,
                AdminFinalPageSize.UNALLOCATED_ICARD_PAGESIZE);
        icCards = (List<IcCard>) map.get(ICommonDAO.OBJ_LIST);
        if (null == icCards) {
            s = 0;
            return SUCCESS;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;
        return SUCCESS;
    }

    /**
     * 回收代理商手中未分配的卡
     * 
     * @return
     */
    public String deleteProxyCard() {

        icCards = adminAssignCardService.searchRecoverProxyCards(ichead,
                icbody1, icbody2, pid);

        s = adminAssignCardService.deleteAssignProxyCard(ichead, icbody1,
                icbody2, pid);

        return SUCCESS;
    }

    public void setAdminAssignCardService(
            IAdminAssignCardService adminAssignCardService) {
        this.adminAssignCardService = adminAssignCardService;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPage_size() {
        return page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public int getCount() {
        return count;
    }

    public List<IcCard> getIcCards() {
        return icCards;
    }

    public int getS() {
        return s;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public void setIcbody2(String icbody2) {
        this.icbody2 = icbody2;
    }

    public void setIcbody1(String icbody1) {
        this.icbody1 = icbody1;
    }

    public void setIchead(String ichead) {
        this.ichead = ichead;
    }
}
